﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NhanAi.Entity;
using NhanAi.DAO;
using NhanAi.DAO.Mix;
using Home.Utils;
using NhanAi.App_Code;
namespace NhanAi.Admin
{
    public partial class EditCPost : BasePage
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            Authenticate();
           if (!IsPostBack)
            {
                int id = TypeWrapper.GetInt32(Request["id"]);
                PostModel daoPost = new PostModel();
                TaxonomyDao daoTax = new TaxonomyDao();
                Post p = daoPost.Read(id, NAConstants.ALL_LANGUAGE);
                hdnId.Value = id.ToString();               
                PostContent.Value = p.Content;
               
               
                cmbStatus.Items.Add(new ListItem("Nháp", NAConstants.POST_STA_DRAFT.ToString()));
                cmbStatus.Items.Add(new ListItem("Cho phép đăng", NAConstants.POST_STA_POST.ToString()));
                
                int index = 0;
                foreach (ListItem item in cmbStatus.Items)
                {
                    if (item.Value == p.Status.ToString())
                    {
                        cmbStatus.SelectedIndex = index;
                    }
                    index++;
                }
                
            }
           SetCurrentPage("Class");
        }
        public void btnUpdateClick(object sender, EventArgs e)
        {
            try
            {
                PostDao daoPost = new PostDao();
                //PostModel modPost = new PostModel();
                int id = TypeWrapper.GetInt32(hdnId.Value);
                Post p = daoPost.Read(id, NAConstants.ALL_LANGUAGE);

                p.Content = PostContent.Value;
                p.ContentEn = "";
                p.Status = int.Parse(cmbStatus.SelectedItem.Value);
             
                p.ModifiedDate = DateTime.Now;


                daoPost.Update(p);
            }
            catch (Exception ex)
            {
                SetMessage("Đã xảy ra lỗi","");
            }
            SetMessage("Cập nhật thành công", "");
        }
     
    }
}